#!/usr/bin/python

###############################
## A base function for plots ##
###############################

#######################################################      
## Set PyRoot Environment and PlotConfig Path first ###
#######################################################
import sys
ROOTSYS = '/afs/atlas.umich.edu/opt/root/lib'
sys.path.append(ROOTSYS)
PlotConfig='../'
PlotConfig2='.'
sys.path.append(PlotConfig)
sys.path.append(PlotConfig2)

#####################
## Import Module  ###
#####################
import array
import os
import glob
from math import sqrt,fabs,sin
from ROOT import TFile,TTree,TChain,TBranch,TH1,TH1F,TList
from ROOT import TLorentzVector
from ROOT import THStack,TCanvas,TLegend,TColor,TPaveText
from ROOT import gStyle,gDirectory

####################
## Import Template #
####################
from plot_template_sig_2D import plot_template_2D

###############
## Plotting ###
###############
RatioSize=0.2
RatioErr=-1
RatioMin,RatioMax=0.5,1.5
RatioAdj=-1

ShowMCErr=1
MCErree=0.03157
MCErrmm=0.01276
MCErrll=0.01584

plot_config='plot_configure.cutflow.alpgen'

#ATLAS='ATLAS For Approval'
ATLAS='ATLAS Internal'
#ATLAS=''
figFormat='all'

histoDir='NOM'
Sig='ZZ->llnn'
CutDirectionX=1
CutDirectionY=1
Profile=1

histoDir='NOM'

yscale=2


####### Axial MET vs FracDiff
CutDirectionX=2
CutDirectionY=-1
Xmin, Xmax=0, 200
Ymin, Ymax=0, 2
RatioMin,RatioMax=0.5,1.5
RebinX=1
RebinY=5
hname=histoDir+'_ee_Zmass_N2_METAx_Et_N2_FracDiff'
hxt='Axial-E_{T}^{miss},ee [GeV]'
hyt='|E_{T}^{miss}-p_{T}^{ee}|/p_{T}^{ee}'
MCErr=MCErree
plot_template_2D(histodir=histoDir,sig=Sig,cutdirectionx=CutDirectionX,cutdirectiony=CutDirectionY,profile=Profile,hname=hname,hxt=hxt,hyt=hyt,xmin=Xmin,xmax=Xmax,ymin=Ymin,ymax=Ymax,hrebinx=RebinX,hrebiny=RebinY,configfile=plot_config)
hname=histoDir+'_mm_Zmass_N2_METAx_Et_N2_FracDiff'
hxt='Axial-E_{T}^{miss},#mu#mu [GeV]'
hyt='|E_{T}^{miss}-p_{T}^{ee}|/p_{T}^{#mu#mu}'
MCErr=MCErrmm
plot_template_2D(histodir=histoDir,sig=Sig,cutdirectionx=CutDirectionX,cutdirectiony=CutDirectionY,profile=Profile,hname=hname,hxt=hxt,hyt=hyt,xmin=Xmin,xmax=Xmax,ymin=Ymin,ymax=Ymax,hrebinx=RebinX,hrebiny=RebinY,configfile=plot_config)


####### Axial MET vs TrackMET
CutDirectionX=2
CutDirectionY=2
Xmin, Xmax=0, 200
Ymin, Ymax=0, 200
RatioMin,RatioMax=0.5,1.5
RebinX=1
RebinY=1
hname=histoDir+'_ee_Zmass_N2_METAx_Et_N2_MET_Track_Et'
hxt='Axial-E_{T}^{miss},ee [GeV]'
hyt='E_{T}^{miss,track},ee [GeV]'
MCErr=MCErree
plot_template_2D(histodir=histoDir,sig=Sig,cutdirectionx=CutDirectionX,cutdirectiony=CutDirectionY,profile=Profile,hname=hname,hxt=hxt,hyt=hyt,xmin=Xmin,xmax=Xmax,ymin=Ymin,ymax=Ymax,hrebinx=RebinX,hrebiny=RebinY,configfile=plot_config)
hname=histoDir+'_mm_Zmass_N2_METAx_Et_N2_MET_Track_Et'
hxt='Axial-E_{T}^{miss},#mu#mu [GeV]'
hyt='E_{T}^{miss,track},#mu#mu [GeV]'
MCErr=MCErrmm
plot_template_2D(histodir=histoDir,sig=Sig,cutdirectionx=CutDirectionX,cutdirectiony=CutDirectionY,profile=Profile,hname=hname,hxt=hxt,hyt=hyt,xmin=Xmin,xmax=Xmax,ymin=Ymin,ymax=Ymax,hrebinx=RebinX,hrebiny=RebinY,configfile=plot_config)

hname=histoDir+'_ee_Zmass_N2_METAx_Et_N2_MET_Track_Cl_Et'
hxt='Axial-E_{T}^{miss},ee [GeV]'
hyt='E_{T}^{miss,track,cl},ee [GeV]'
MCErr=MCErree
plot_template_2D(histodir=histoDir,sig=Sig,cutdirectionx=CutDirectionX,cutdirectiony=CutDirectionY,profile=Profile,hname=hname,hxt=hxt,hyt=hyt,xmin=Xmin,xmax=Xmax,ymin=Ymin,ymax=Ymax,hrebinx=RebinX,hrebiny=RebinY,configfile=plot_config)
hname=histoDir+'_mm_Zmass_N2_METAx_Et_N2_MET_Track_Cl_Et'
hxt='Axial-E_{T}^{miss},#mu#mu [GeV]'
hyt='E_{T}^{miss,track,cl},#mu#mu [GeV]'
MCErr=MCErrmm
plot_template_2D(histodir=histoDir,sig=Sig,cutdirectionx=CutDirectionX,cutdirectiony=CutDirectionY,profile=Profile,hname=hname,hxt=hxt,hyt=hyt,xmin=Xmin,xmax=Xmax,ymin=Ymin,ymax=Ymax,hrebinx=RebinX,hrebiny=RebinY,configfile=plot_config)

hname=histoDir+'_ee_Zmass_N2_METAx_Et_N2_MET_Track_Siglep_Et'
hxt='Axial-E_{T}^{miss},ee [GeV]'
hyt='E_{T}^{miss,track,signal lepton},ee [GeV]'
MCErr=MCErree
plot_template_2D(histodir=histoDir,sig=Sig,cutdirectionx=CutDirectionX,cutdirectiony=CutDirectionY,profile=Profile,hname=hname,hxt=hxt,hyt=hyt,xmin=Xmin,xmax=Xmax,ymin=Ymin,ymax=Ymax,hrebinx=RebinX,hrebiny=RebinY,configfile=plot_config)
hname=histoDir+'_mm_Zmass_N2_METAx_Et_N2_MET_Track_Siglep_Et'
hxt='Axial-E_{T}^{miss},#mu#mu [GeV]'
hyt='E_{T}^{miss,track,signal lepton},#mu#mu [GeV]'
MCErr=MCErrmm
plot_template_2D(histodir=histoDir,sig=Sig,cutdirectionx=CutDirectionX,cutdirectiony=CutDirectionY,profile=Profile,hname=hname,hxt=hxt,hyt=hyt,xmin=Xmin,xmax=Xmax,ymin=Ymin,ymax=Ymax,hrebinx=RebinX,hrebiny=RebinY,configfile=plot_config)



dir='Sig_2D_'+histoDir
if not os.path.isdir(dir): os.mkdir(dir)
cmd='mv *.pdf *.png *.eps *.root '+dir
os.system(cmd)
